package com.chaos.eurekaproducer.leetCode;

import apple.laf.JRSUIUtils;
import com.chaos.eurekaproducer.basic.TreeNode;

/**
 * @author liaopeng
 * @title: Offer26
 * @projectName eureka-producer
 * @description:
 *请完成一个函数，输入一个二叉树，该函数输出它的镜像。
 *
 * 例如输入：
 *
 *      4
 *    /   \
 *   2     7
 *  / \   / \
 * 1   3 6   9
 * 镜像输出：
 *
 *      4
 *    /   \
 *   7     2
 *  / \   / \
 * 9   6 3   1
 *
 *
 *
 * 示例 1：
 * 输入：root = [4,2,7,1,3,6,9]
 * 输出：[4,7,2,9,6,3,1]
 *
 *
 * @date 2021/6/11下午2:19
 */
public class Offer27 {
    public static TreeNode mirrorTree(TreeNode root) {
        if (root==null){
            return root;
        }
        TreeNode temp = root.getRight();
        TreeNode left =mirrorTree(root.getLeft());
        TreeNode right = mirrorTree(temp);
        root.setRight(left);
        root.setLeft(right);
        return root;
    }

    public static void main(String[] args) {
        int[] preorder = new int[]{3,9,20,15,7};
        int[] inorder = new int[]{9,3,15,20,7};
        TreeNode root = Offer07.buildTreeNode(preorder, inorder);
        TreeNode treeNode = mirrorTree(root);
        System.out.println(treeNode);
    }
}
